<!--验证文件数量-->
function validateFileCount(input) {
    if (input.files.length > 10) {
        alert('最多只能选择10个文件');
        input.value = ''; // 清除选择
    }
}


<!--用PDF转换成Markdown submit-->
document.getElementById('pdfForm').addEventListener('submit', function (e) {
    e.preventDefault();

    const formData = new FormData(this);
    const submitBtnPdf = document.getElementById('submitBtnPDF');
    const originalBtnText = submitBtnPdf.textContent;

    // 显示加载状态
    submitBtnPdf.disabled = true;
    submitBtnPdf.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> 处理中...';

    fetch(`${window.basePath}tool/convert-pdf`, {
        method: 'POST',
        body: formData
    })
        .then(response => response.json())
        .then(data => {
            if (data.error) {
                alert(data.error);
                return;
            }

            const resultSection = document.getElementById('resultSectionPDF');
            const resultsContainer = document.getElementById('resultsContainerPDF');
            resultsContainer.innerHTML = '';

            data.results.forEach(result => {
                const resultItem = document.createElement('div');
                resultItem.className = 'mb-4';

                resultItem.innerHTML = `
                        <h5>${result.fileName}</h5>
                       <!-- <div class="markdown-preview">${result.content}</div>
                        <button class="btn btn-sm btn-primary copy-btn"
                                onclick="copyMarkdown(this)">复制到剪贴板</button>
                        <hr> -->
                    `;

                resultsContainer.appendChild(resultItem);
            });

            resultSection.style.display = 'block';
            // 滚动到结果区域
            resultSection.scrollIntoView({behavior: 'smooth'});
        })
        .catch(error => {
            console.error('Error:', error);
            alert('处理过程中发生错误');
        })
        .finally(() => {
            submitBtnPdf.disabled = false;
            submitBtnPdf.textContent = originalBtnText;
        });
});


<!--用Excel转换成Markdown submit-->
document.getElementById('uploadForm').addEventListener('submit', function (e) {
    e.preventDefault();
    const formData = new FormData(this);
    const submitBtn = document.getElementById('submitBtn');
    const originalBtnText = submitBtn.textContent;

    // 显示加载状态
    submitBtn.disabled = true;
    submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> 处理中...';

    fetch(`${window.basePath}tool/convert`, {
        method: 'POST',
        body: formData
    })
        .then(response => response.json())
        .then(data => {
            if (data.error) {
                alert(data.error);
                return;
            }

            const resultSection = document.getElementById('resultSection');
            const resultsContainer = document.getElementById('resultsContainer');
            resultsContainer.innerHTML = '';

            data.results.forEach(result => {
                const resultItem = document.createElement('div');
                resultItem.className = 'mb-4';

                resultItem.innerHTML = `
                        <h5>${result.fileName}</h5>
                       <!-- <div class="markdown-preview">${result.content}</div>
                        <button class="btn btn-sm btn-primary copy-btn"
                                onclick="copyMarkdown(this)">复制到剪贴板</button>
                        <hr> -->
                    `;

                resultsContainer.appendChild(resultItem);
            });

            resultSection.style.display = 'block';
            // 滚动到结果区域
            resultSection.scrollIntoView({behavior: 'smooth'});
        })
        .catch(error => {
            console.error('Error:', error);
            alert('处理过程中发生错误');
        })
        .finally(() => {
            submitBtn.disabled = false;
            submitBtn.textContent = originalBtnText;
        });
});